var paraurl = "http://admin.zhongguojiaoyunet.com/";
var imgurls = "http://eduqiniu.hihaoge.me";
var tm = new Date().getTime();
var rules_phone = /1[3456789]\d{9}$/;
if (!window.zm) {
	zm = {};
};
if (!window.xzm) {
	xzm = {};
};
/**
 * 将时间转换成时间戳zm.gTimes()
 * @param DateTime 为时间格式下的时间 2018/06/14 13:00:00或2018-06-14 13:00:00
 * @returns {number}
 * @constructor
 */
zm.gTimes = function (DateTime) {
	var oDate = new Date(Date.parse(DateTime.replace(/-/g, "/")));
	var Unix = oDate.getTime();
	return Unix;
}
/**
 * 2,时间挫转换时间zm.gTime(UnixTime,ShowTime)；
 * UnixTime必须为number如：zm.gTime(Number(time),3)
 * 后台返回的一般为秒而我们是毫秒需要*1000
 */

zm.gTime = function (UnixTime, ShowTime) {
	var ToUnix = new Date(Number(UnixTime));
	var Years = ToUnix.getFullYear(); //获取年 例子：2018
	var Month = ToUnix.getMonth() + 1; //获取月(0-11,0代表1月)
	var Day = ToUnix.getDate(); //获取日（0-31）
	var Week = ToUnix.getDay(); //获取星期（0-6；0代表星期天）
	var Hours = ToUnix.getHours(); //获取小时（0-23）
	var Minutes = ToUnix.getMinutes(); //获取分钟（0-59）
	var Seconds = ToUnix.getSeconds(); //获取秒
	var DaTime;
	if (ShowTime == 2) {
		DaTime = Years + "/" + DeCa(Month) + "/" + DeCa(Day) + " " + DeCa(Hours) + ":" + DeCa(Minutes) + ":" + DeCa(Seconds);
	} else if (ShowTime == 3) {
		DaTime = Years + "年" + DeCa(Month) + "月" + DeCa(Day) + "日 " + DeCa(Hours) + ":" + DeCa(Minutes) + ":" + DeCa(Seconds);
	} else if (ShowTime == 4) {
		DaTime = Years + "年" + DeCa(Month) + "月" + DeCa(Day) + "日";
	} else if (ShowTime == 5) {
		DaTime = Years + "/" + DeCa(Month) + "/" + DeCa(Day);
	} else if (ShowTime == 6) {
		DaTime = Years + "-" + DeCa(Month) + "-" + DeCa(Day);
	} else if (ShowTime == 7) {
		DaTime = DeCa(Hours) + ":" + DeCa(Minutes) + ":" + DeCa(Seconds);
	} else if (ShowTime == 8) {
		DaTime = DeCa(Hours) + "时" + DeCa(Minutes) + "分" + DeCa(Seconds) + "秒";
	} else if (ShowTime == 9) {
		DaTime = "星期" + Week;
	} else if (ShowTime == 10) {
		DaTime = NumBerToHanZi(Years) + "年" + NumBerToHanZi(Month) + "月" + NumBerToHanZi(Day) + "日 星期" + NumBerToHanZi(Week);
	} else if (ShowTime == 11) {
		DaTime = Years + "-" + DeCa(Month) + "-" + DeCa(Day) + " " + DeCa(Hours) + ":" + DeCa(Minutes) + ":" + DeCa(Seconds) + " 星期" + Week;
	} else if (ShowTime == 12) {
		DaTime = Years + "/" + DeCa(Month) + "/" + DeCa(Day) + " " + DeCa(Hours) + ":" + DeCa(Minutes) + ":" + DeCa(Seconds) + " 星期" + Week;
	} else if (ShowTime == 13) {
		DaTime = Years + "年" + DeCa(Month) + "月" + DeCa(Day) + "日 " + DeCa(Hours) + "时" + DeCa(Minutes) + "分" + DeCa(Seconds) + "秒 星期" + Week;
	} else {
		DaTime = Years + "-" + DeCa(Month) + "-" + DeCa(Day) + " " + DeCa(Hours) + ":" + DeCa(Minutes) + ":" + DeCa(Seconds);
	}
	return DaTime;
}

function DeCa(Natural) {
	var NaturalNum;
	if (Natural < 10) {
		NaturalNum = "0" + Natural;
	} else {
		NaturalNum = Natural;
	}
	return NaturalNum;
}
//将阿拉伯数字转换成汉字
zm.gHanzi = function (Numbers) {
	var strIns, chnStr = '';
	var chnNumChar = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
	while (Numbers > 0) {
		var v = Numbers % 10;
		strIns = chnNumChar[v];
		chnStr = chnNumChar[v] + chnStr;
		Numbers = Math.floor(Numbers / 10);
	}
	return chnStr;
}
// 计算时间差
zm.gTimec = function (EndTime) {
	//如果为时间戳
	var EndTimes = new Date(EndTime).getTime(); //结束时间
	var NowTime = new Date().getTime();
	//当前时间
	var DeltaT = EndTimes - NowTime;
	//计算出相差天数
	var days = Math.floor(DeltaT / (24 * 3600 * 1000));
	//计算出小时数
	var leave1 = DeltaT % (24 * 3600 * 1000);
	var H = Math.floor(leave1 / (3600 * 1000));
	//计算相差分钟数
	var leave2 = leave1 % (3600 * 1000);
	var M = Math.floor(leave2 / (60 * 1000));
	//计算相差秒数
	var leave3 = leave2 % (60 * 1000);
	var S = Math.round(leave3 / 1000);
	var reminder;
	if (DeltaT > 0) {
		if (days != "") {
			reminder = days + "天 " + H + "小时 " + M + " 分钟" + S + " 秒";
		} else if (days == "" || H != "") {
			reminder = H + "小时 " + M + " 分钟" + S + " 秒";
		}
	} else {
		reminder = "请注意！时间到了！";
	}
	return reminder;
}
//取页面url参数值var gps = zm.gParaurl()  var id = gps.id
zm.gParaurl = function () {
	var qs = {};
	var url = decodeURIComponent(window.location.href);
	if (zm.isredirect) {
		if (url.indexOf('htm') > -1) {
			url = url.substring(url.indexOf('/', 7) + 1);
			var paras = ["pageid", "id"];
			var prm = url.split('/');
			if (url.indexOf("_") > -1) {
				prm = url.split('_')
			}
			for (var p in prm) {
				var index = prm[p].split('.');
				if (/^\d+$/.test(index[0])) {
					qs[paras[p]] = index[0]
				}
			}
		} else {
			url = url.substring(url.indexOf('/', 7) + 1);
			var prm = url.split('/');
			if (/^\d+$/.test(prm[0])) {
				qs.pageid = prm[0]
			}
		}
	}
	if (url.indexOf('?') > -1) {
		url = url.substring(url.indexOf('?') + 1);
		var prm = url.split('&');
		for (var p in prm) {
			if (prm[p]) {
				var sp = prm[p].split('=');
				if (sp.length > 1) {
					var spkey = sp[0];
					var spvalue = sp[1];
					if (spvalue.indexOf('#') > -1) {
						spvalue = spvalue.substring(0, spvalue.indexOf('#'))
					}
					qs[spkey] = spvalue
				}
			}
		}
	}
	return qs
};
/**
 * 数组去重
 * zm.arryQc(arry)
 */
zm.arryQc = function (arry) {
	for (var i = 0; i < arry.length; i++) {
		for (var j = i + 1; j < arry.length; j++) {
			if (arry[i] == arry[j]) {
				arry.splice(j, 1)
			}
		}
	}
	return arry;
}
/**
 * 数字递增
 * html:<span class="zmnumberdz" m-start="0" m-end="1565464654" m-speed="100">0</span>
 * js调用zm.numberDz()
 * para:class="zmnumberdz";m-start="0";m-end="1565464654";m-speed="100"
 */
zm.numberDz = function () {
	$(".zmnumberdz").each(function (i, v) {
		var start = Number(v.getAttribute("m-start"));
		var end = Number(v.getAttribute("m-end"));
		var speed = Number(v.getAttribute("m-speed"));
		var timer = "timer" + i;
		timer = setInterval(function () {
			if (start < end) {
				var num = Math.ceil((end - start) / 2);
				start = start + num;
				v.innerText = start;
			} else {
				clearInterval(timer);
			}
		}, speed)
	})
}
/**
 * 生成n-m之间随机数
 * zm.randomNum(min, max)
 */
zm.randomNum = function (min, max) {
	return Math.floor(Math.random() * (max - min) + min);
}
/**
 * 生成随机颜色
 * zm.randomNum(min, max)
 */
zm.randomColor = function (min, max) {
	var r = zm.randomNum(min, max);
	var g = zm.randomNum(min, max);
	var b = zm.randomNum(min, max);
	return "rgb(" + r + "," + g + "," + b + ")";
}
/**
 * 生成验证码*
 * zm.createCode(num,type)
 * para:num验证码位数;type验证码类型(0普通验证码1加减算术验证码)
 * html:<canvas onclick="zm.createCode(5,1)" id="ccode" height="100" width="300"></canvas>
 */
zm.createCode = function (num, type) {
	var canvas = document.getElementById('ccode');
	var letterStr = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9";
	letterStr = letterStr.split(",");
	var operation = ["+", "-"]
	var ctx = canvas.getContext('2d');
	ctx.fillStyle = zm.randomColor(0, 255);
	ctx.fillRect(0, 0, canvas.width, canvas.height);
	var code = "";
	if (type == 0) {
		for (var i = 0; i < num; i++) { //生成随机验证码
			var a = letterStr[zm.randomNum(0, letterStr.length)];
			code = code + a;
			ctx.font = zm.randomNum(canvas.height / 2, canvas.height) + 'px SimHei';
			ctx.fillStyle = zm.randomColor(50, 160);
			var x = canvas.width / 5 * i; //设置选择角度
			var y = canvas.height / 2;
			var deg = zm.randomNum(-20, 20);
			ctx.translate(x, y);
			ctx.rotate(deg * Math.PI / 180);
			ctx.fillText(a, 0, canvas.height / 4);
			ctx.rotate(-deg * Math.PI / 180); //恢复旋转角度
			ctx.translate(-x, -y);
		}
	} else {
		var operation_index = zm.randomNum(0, 2);
		var num1 = zm.randomNum(0, 100);
		var num2 = zm.randomNum(0, 100);
		var frist;
		var second;
		if (num1 > num2) {
			frist = num1;
			second = num2;
		} else {
			frist = num2;
			second = num1;
		}
		if (operation_index == 0) {
			code = frist + second;
		} else {
			code = frist - second;
		}
		var codeshow = [frist, operation[operation_index], second, "=", "?"]
		for (var i = 0; i < codeshow.length; i++) {
			ctx.font = zm.randomNum(canvas.height / 2.5, canvas.height / 1.5) + 'px SimHei';
			ctx.fillStyle = zm.randomColor(50, 160);
			var x = canvas.width / 5 * i; //设置选择角度
			var y = canvas.height / 2;
			var deg = zm.randomNum(-10, 10);
			ctx.translate(x, y);
			ctx.rotate(deg * Math.PI / 180);
			ctx.fillText(codeshow[i], 0, canvas.height / 4);
			ctx.rotate(-deg * Math.PI / 180); //恢复旋转角度
			ctx.translate(-x, -y);
		}
	}
	for (var i = 0; i < num; i++) { //添加干扰线
		ctx.strokeStyle = zm.randomColor(40, 180);
		ctx.beginPath();
		ctx.moveTo(zm.randomNum(0, canvas.width), zm.randomNum(0, canvas.height));
		ctx.lineTo(zm.randomNum(0, canvas.width), zm.randomNum(0, canvas.height));
		ctx.stroke();
	}
	for (var i = 0; i < canvas.width / num; i++) { //添加干扰点
		ctx.fillStyle = zm.randomColor(0, 255);
		ctx.beginPath();
		ctx.arc(zm.randomNum(0, canvas.width), zm.randomNum(0, canvas.height), 1, 0, 2 * Math.PI);
		ctx.fill();
	}
	canvas.setAttribute("code", code);
}


/**
 * zm.alert()
 */
zm.alert = function (value, type) {
	var htmls;
	if (type == "danger") {
		htmls = '<div class="zm-alertbg zm-tbox"><div class="zm-alertbox zm-alertboxd"><p>' + value + '</p></div></div>'
	} else if (type == "success") {
		htmls = '<div class="zm-alertbg zm-tbox"><div class="zm-alertbox zm-alertboxs"><p>' + value + '</p></div></div>'
	}
	$("body").append(htmls);
	$("body").on("click", ".zm-tbox", function () {
		$(".zm-tbox").remove();
	});
}
/**
 * 星级打分器
 * zm.star(star1,star2)
 * html部分<div class="zm-star" num="5" starnum="0"></div>;
 * num初始化星星数量；starnum用户选择中星星数量（可通过$(".zm-star").attr("starnum")获得）
 * 传入参数star1,star2选中前后图片,不传则为默认图片
 */
zm.star = function (star1, star2) {
	if (star1 == undefined) {
		star1 = "data:img/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABAElEQVRYhe2WUQ3DIBCGkYCESaiESqgEJFRCHVTCJFQB+SUgAQlI2B56TVgDHeVuNFl6yb1Bvw84jip1xx2MADAA6K4UcADcVXAD4EU5tIZrWv0m4FsLjBF8S9MKrgH4hEBoImCtnRLw3+4CrbqjrQ8HAoHG1F/NHWymYjuCHuVC3zDFUjSpBlaSc6mEY4JS+QSgzxyDpIQrhkcSD9SffZz+NDyS6JjwAO5jBaBnwGXeiC/NJ5nW2kkErpRSWCv4UoGa3rBICtRcSVEBX1OEUnCdA1Bx5upDTGDfCzawjsbojEhdA9oJ9DlwYqzG598S/48Z61M6nl0NzTFsgTv+Pt4eY7UKQjzXAAAAAABJRU5ErkJggg==";
		star2 = "data:img/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABNUlEQVRYhe2WwY2DMBBFXQIl7DEeX1zClpASKIES6IASUgKlUALH4PFhJBjO7AFnRQhEYBxQJL40N6T3x575WIhTpzaoNvLKqPRhBhihYITiEHiNKmaEjhG62sjrrnAiHbnuO1flrga4kskA3p8CqngXuOu+HBtgBNrFQGMgnYB/9hT6rpV2R09zBhiB+m82rOYTzKrMDds76Gy1FnK2Kus3ZqGp1kLuA1tUVmWLTIxWLFTdiHS04hqCmigWw/9N3C8/vnc/qnI1/CFGpTfCafPPqrlffn3hwf4R78JnrhoDaRC4EEIwwu1QAz7Z0FrIgxnwWcnQBkqfIQwCd6E0CXDDOTcfYQxMZAE1BtJhuDiTL0a8A2ioQQ68gMci0tHzaynAi7lGFXMlk7XdcCWT3Z5pp75af/ozdc0TVXl4AAAAAElFTkSuQmCC";
	}
	var num = parseInt($(".zm-star").attr("num"));
	var starhtml = ""
	for (var i = 0; i < num; i++) {
		starhtml += '<img startindex="' + i + '" src="' + star1 + '" />'
	}
	$(".zm-star").append(starhtml);
	$("body").on("click", ".zm-star img", function () {
		$(".zm-star img").attr("src", star1);
		var startindex = parseInt($(this).attr("startindex"));
		for (var i = 0; i <= startindex; i++) {
			$(".zm-star img").eq(i).attr("src", star2);
		}
		$(".zm-star").attr("starnum", startindex + 1);
	})
}